package cn.hill4j.tool.spring.ext.mvc.encryption;

import cn.hill4j.tool.spring.ext.mvc.exception.RequestDesInvokerException;
import org.springframework.core.MethodParameter;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ResponseEncStrategy {
    /**
     * 策略处理bean
     */
    private Object strategyBean;
    /**
     * 策略处理具体方法
     */
    private Method strategyMethod;
    /**
     * @author hillchen
     * Description: 构造方法
     * Date: 2023/8/13 00:28
     * @param strategyBean 策略处理bean
     * @param strategyMethod 策略处理具体方法
     **/
    public ResponseEncStrategy(Object strategyBean, Method strategyMethod) {
        this.strategyBean = strategyBean;
        this.strategyMethod = strategyMethod;
    }
    /**
     * @author hillchen
     * Description: 执行解密策略
     * Date: 2023/8/13 00:29
     * @param result 需要解密请求参数
     * @return Object
     **/
    public Object invokeStrategy(Object result) throws RequestDesInvokerException {
        try {
            return strategyMethod.invoke(strategyBean,result);
        }catch  (InvocationTargetException | IllegalAccessException e) {
            throw new RequestDesInvokerException("之前request解密失败",e);
        }
    }
}
